package it.asvp.asvp_portal.data.entity.member;


import static javax.persistence.GenerationType.IDENTITY;
import it.asvp.asvp_portal.asvp_util.enumerative.Role;
import it.asvp.asvp_portal.data.entity.domain.BaseEntity;
import it.asvp.asvp_portal.data.entity.domain.File;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

@SuppressWarnings("serial")
@Entity
@Table(name = "council", catalog = "asvp_db", uniqueConstraints = @UniqueConstraint(columnNames = {
		"id_member", "start_year" }))
public class Council extends BaseEntity {

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	private Long id;
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_member", nullable = false)
	private Member member;
	
	@Enumerated(EnumType.STRING)
	private Role role;
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_picture")
	@Cascade({CascadeType.ALL})
	private File picture;
	
	@Column(name = "start_year", nullable = false)
	private int startYear;
	
	@Column(name = "end_year", nullable = false)
	private int endYear;
	
	@Column(name = "description", nullable = false, length = 1000)
	private String description;
	
	@Column(name = "current")
	private Boolean current;

	public Council() {
	}

	public Council(Member member, Role role, int startYear, int endYear,
			String description,File picture, Date createdOn, Date lastUpdate) {
		
		this.member = member;
		this.role = role;
		this.startYear = startYear;
		this.endYear = endYear;
		this.description = description;
		this.picture=picture;
		this.createdOn = createdOn;
		this.lastUpdate = lastUpdate;
	}



	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	
	public Member getMember() {
		return this.member;
	}

	public void setMember(Member member) {
		this.member = member;
	}

	
	public Role getRole() {
		return this.role;
	}

	public void setRole(Role role) {
		this.role = role;
	}


	public File getPicture() {
		return this.picture;
	}

	public void setPicture(File file) {
		this.picture = file;
	}

	
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	public int getStartYear() {
		return this.startYear;
	}

	public void setStartYear(int startYear) {
		this.startYear = startYear;
	}

	public int getEndYear() {
		return this.endYear;
	}

	public void setEndYear(int endYear) {
		this.endYear = endYear;
	}
	
	public Boolean getCurrent() {
		return this.current;
	}

	public void setCurrent(Boolean current) {
		this.current = current;
	}

}
